package com.example.hotel_lxy.ui.fragment;


import android.content.Intent;
import android.graphics.Color;
import android.graphics.Typeface;
import android.net.Uri;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
import android.util.TypedValue;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.RadioGroup;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.example.hotel_lxy.R;
import com.example.hotel_lxy.bean.BeanBean;
import com.example.hotel_lxy.bean.EventBusBean;
import com.example.hotel_lxy.bean.FOrderAllBean;
import com.example.hotel_lxy.bean.RvStandardTypeBean;
import com.example.hotel_lxy.bean.ScheduledBean;
import com.example.hotel_lxy.net.Api;
import com.example.hotel_lxy.ui.activity.LoginActivity;
import com.example.hotel_lxy.ui.activity.ReserveInformationActivity;
import com.example.hotel_lxy.ui.activity.SetUpReserveActivity;
import com.example.hotel_lxy.ui.dialog.DialPhoneDialog;
import com.example.hotel_lxy.ui.main.CalendarActivity;
import com.example.hotel_lxy.utils.DatePhotoUtils;
import com.example.hotel_lxy.utils.DateUtils;
import com.example.hotel_lxy.utils.EmptyUtils;
import com.example.hotel_lxy.utils.SPUtils;
import com.google.android.material.tabs.TabLayout;
import com.luck.picture.lib.tools.ToastUtils;
import com.scwang.smartrefresh.layout.SmartRefreshLayout;
import com.ysxsoft.common_base.adapter.BaseQuickAdapter;
import com.ysxsoft.common_base.adapter.BaseViewHolder;
import com.ysxsoft.common_base.base.BaseFragment;
import com.ysxsoft.common_base.base.RBaseAdapter;
import com.ysxsoft.common_base.base.RViewHolder;
import com.ysxsoft.common_base.base.frame.list.IListAdapter;
import com.ysxsoft.common_base.base.frame.list.ListManager;
import com.ysxsoft.common_base.utils.JsonUtils;
import com.ysxsoft.common_base.view.widgets.MultipleStatusView;
import com.zhy.http.okhttp.OkHttpUtils;
import com.zhy.http.okhttp.callback.StringCallback;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;
import okhttp3.Call;

/***
 *
 * 全部
 *
 */
public class FragmentWhole extends BaseFragment implements IListAdapter<FOrderAllBean.DataBean.ListBean> {
    RadioGroup radioGroup;
    @BindView(R.id.recyclerView)
    RecyclerView recyclerView;
    @BindView(R.id.multipleStatusView)
    MultipleStatusView multipleStatusView;
    @BindView(R.id.smartRefresh)
    SmartRefreshLayout smartRefresh;
    @BindView(R.id.text_type)
    TextView textType;
    @BindView(R.id.line_all)
    LinearLayout lineAll;
    @BindView(R.id.edit_search)
    EditText editSearch;
    private List<Officetype> pop_mlist_office = new ArrayList<>();
    private List<Officetype> pop_mlist_type = new ArrayList<>();
    private PopupWindow mpopup_all_office;
    private PopupWindow mpopup_all_type;
    @BindView(R.id.text_field_number)
    TextView textFieldNumber; //场数
    @BindView(R.id.text_table_number)
    TextView textTableNumber;//桌数
    @BindView(R.id.text_deposit_number)
    TextView textDepositNumber;//押金
    @BindView(R.id.text_total_amount)
    TextView textTotalAmount;//总金额

    @BindView(R.id.tabs)
    TabLayout tabs;
    private String begin = "";
    private String end = "";
    private String search = "";
    private String data = "1";
    private String all_type = "1";
    ListManager<FOrderAllBean.DataBean.ListBean> manager;
    private List<String> mTitles = new ArrayList<>();


    private String tid = "";
    private String bid = "";
    private String director_id = "";
    @BindView(R.id.text_all_office)
    TextView textAllOffice;
    @BindView(R.id.text_all_type)
    TextView textAllType;
    TextView textStartTime;
    TextView timeEndTime;
    private int data_type;

    public RadioGroup getRadioGroup() {
        return radioGroup;
    }

    public void setRadioGroup(RadioGroup radioGroup) {
        this.radioGroup = radioGroup;
    }


    public TextView getTextStartTime() {
        return textStartTime;
    }

    public void setTextStartTime(TextView textStartTime) {
        this.textStartTime = textStartTime;
    }

    public TextView getTimeEndTime() {
        return timeEndTime;
    }

    public void setTimeEndTime(TextView timeEndTime) {
        this.timeEndTime = timeEndTime;
    }

    @Override
    public int getLayoutId() {
        return R.layout.fragment_whole;
    }


    @Override
    protected void doWork(View view) {
        if (!EventBus.getDefault().isRegistered(this)) {
            EventBus.getDefault().register(this);  //事件的注册
        } else {
            EventBus.getDefault().unregister(this); //解除注册
            EventBus.getDefault().register(this);  //事件的注册
        }
//        begin=textStartTime.getText().toString();
//        end=timeEndTime.getText().toString();
        String string = SPUtils.get(getContext(), "id", "").toString();
        director_id = string + "";
        showView(view);
        //宴会厅
        showOffice();
        showOfficeType( );
        ShowTab();
        try {
            Changed();
        } catch (Exception e) {
            e.printStackTrace();
        }
        textStartTime.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                data_type = 1;
                CalendarActivity.start(3);
            }
        });
        timeEndTime.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                data_type = 2;
                CalendarActivity.start(3);
            }
        });

    }

    private void ShowTab() {
        mTitles.add("汇总");
        mTitles.add("本月");
        mTitles.add("本季度");
        mTitles.add("本年");
        for (String title : mTitles) {
            tabs.addTab(tabs.newTab().setText(title));
        }
        tabs.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
            @Override
            public void onTabSelected(TabLayout.Tab tab) {
                int position = tab.getPosition();

                if (EmptyUtils.isNotEmpty(position)) {
                     textStartTime.setText("");
                     timeEndTime.setText("");
                    switch (position) {
                        case 0:
                            textStartTime.setText("");
                            timeEndTime.setText("");
                            begin = "";
                            end = "";
                            all_type = "1";
                            tabs.getTabAt(position).select();
                            request(1);
                            break;
                        case 1:
                            DateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM");
                            Date date = new Date(System.currentTimeMillis());//获取当前时间
                            String currentDate = simpleDateFormat.format(date);
                            String[] split = currentDate.split("-");
                            int monthLastDay = DateUtils.getMonthLastDay(Integer.valueOf(split[0]), Integer.parseInt(split[1]));
                            textStartTime.setText(currentDate+"-01");
                            timeEndTime.setText(currentDate+"-"+monthLastDay);
                            begin = currentDate+"-01";
                            end = currentDate+"-"+monthLastDay;
                            all_type = "2";
                            tabs.getTabAt(position).select();
                            request(1);
                            break;
                        case 2:
                            DateFormat simpleDateFormatq = new SimpleDateFormat("yyyy-MM");
                            Date dateq = new Date(System.currentTimeMillis());//获取当前时间
                            String currentDateq = simpleDateFormatq.format(dateq);
                            String[] splitq = currentDateq.split("-");
                            int  s=  Integer.valueOf(splitq[1]);
                            if(s>=1&&s<=3){
                                textStartTime.setText(splitq[0]+"-01-01");
                                timeEndTime.setText(splitq[0]+"-03-31");
                            }else if(s>=4&&s<=6){
                                textStartTime.setText(splitq[0]+"-04-01");
                                timeEndTime.setText(splitq[0]+"-06-30");
                            }else if(s>=7&&s<=9){
                                textStartTime.setText(splitq[0]+"-07-01");
                                timeEndTime.setText(splitq[0]+"-09-30");
                            }
                            else if(s>=10&&s<=11){
                               textStartTime.setText(splitq[0]+"-10-01");
                                timeEndTime.setText(splitq[0]+"-12-31");
                            }
                            begin = textStartTime.getText().toString().trim();
                            end = timeEndTime.getText().toString().trim();
                            all_type = "3";
                            tabs.getTabAt(position).select();
                            request(1);
                            break;
                        case 3:
                            DateFormat simpleDateFormats = new SimpleDateFormat("yyyy");
                            Date dates = new Date(System.currentTimeMillis());//获取当前时间
                            String currentDates = simpleDateFormats.format(dates);
                            textStartTime.setText(currentDates+"-01-01");
                            timeEndTime.setText(currentDates+"-12-31");
                            begin = currentDates+"-01-01";
                            end = currentDates+"-12-31";
                            all_type = "4";
                            tabs.getTabAt(position).select();
                            request(1);
                            break;
                    }
                    tabs.post(new Runnable() {
                        @Override
                        public void run() {
                            tabs.setSelectedTabIndicatorColor(Color.parseColor("#FFCA00"));
                        }
                    });
                }
            }

            @Override
            public void onTabUnselected(TabLayout.Tab tab) {

            }

            @Override
            public void onTabReselected(TabLayout.Tab tab) {
                tabs.setSelectedTabIndicatorColor(Color.parseColor("#FFCA00"));
            }
        });

    }




    private void showView(View view) {
        manager = new ListManager(this);
        manager.init(view);
        manager.getAdapter().setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(BaseQuickAdapter adapter, View view, int position) {

            }
        });
        manager.getAdapter().setOnLoadMoreListener(new BaseQuickAdapter.RequestLoadMoreListener() {
            @Override
            public void onLoadMoreRequested() {
                request(manager.nextPage());
            }
        }, recyclerView);

        request(1);
    }

    private void Changed() {
        editSearch.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {

            }

            @Override
            public void afterTextChanged(Editable s) {
                search = s.toString();
                request(1);
            }
        });
        editSearch.setOnEditorActionListener(new TextView.OnEditorActionListener() {
            @Override
            public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
                return (event.getKeyCode() == KeyEvent.KEYCODE_ENTER);
            }
        });
        radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                switch (checkedId) {
                    case R.id.rb1:
                        data = "1";
                        textType.setText("预定日期");
                        break;
                    case R.id.rb2:
                        textType.setText("宴会日期");
                        data = "2";
                        break;
                }
                request(1);
            }
        });
    }

    private void showOffice() {
        OkHttpUtils.post()
                .url(Api.POST_INDEX_SCHEDULED)
                .addHeader("flag", SPUtils.get(getContext(), "token", "").toString())
                .tag(this)
                .build()
                .execute(new StringCallback() {
                    @Override
                    public void onError(Call call, Exception e, int id) {
                        Log.e("TAG", "宴会厅onError   " + e.getMessage());
                    }

                    @Override
                    public void onResponse(String response, int id) {
                        Log.e("TAG", "宴会厅onResponse   " + response);
                        BeanBean beanBean = JsonUtils.parseByGson(response, BeanBean.class);
                        if (beanBean.getCode().equals("4")) {
                            SPUtils.put(getContext(), "token", "");
                            Intent intent = new Intent(getContext(), LoginActivity.class).
                                    setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
                            startActivity(intent);
                            return;
                        }
                        ScheduledBean scheduledBean = JsonUtils.parseByGson(response, ScheduledBean.class);
                        Officetype officetypes = new Officetype();
                        officetypes.setId("0");
                        officetypes.setName("全部");
                        pop_mlist_office.add(officetypes);
                        for (int i = 0; i < scheduledBean.getData().size(); i++) {
                            Officetype officetype = new Officetype();
                            officetype.setId(scheduledBean.getData().get(i).getId() + "");
                            officetype.setName(scheduledBean.getData().get(i).getName());
                            pop_mlist_office.add(officetype);
                        }

                    }
                });
    }


    private void showOfficeType() {
        pop_mlist_type.clear();
        OkHttpUtils.post()
                .url(Api.POST_SCHEDULED_TYPE)
                .addHeader("flag", SPUtils.get(getContext(), "token", "").toString())
//                .addParams("bid", "" + id)
                .tag(this)
                .build()
                .execute(new StringCallback() {
                    @Override
                    public void onError(Call call, Exception e, int id) {
                        Log.e("TAG", "获取宴会厅的类型onError   " + e.getMessage());
                    }

                    @Override
                    public void onResponse(String response, int id) {
                        Log.e("TAG", "获取宴会厅的类型onResponse   " + response);
                        BeanBean beanBean = JsonUtils.parseByGson(response, BeanBean.class);
                        if (beanBean.getCode().equals("4")) {
                            SPUtils.put(getContext(), "token", "");
                            Intent intent = new Intent(getContext(), LoginActivity.class).
                                    setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
                            startActivity(intent);
                            return;
                        }
                        RvStandardTypeBean rvStandardTypeBean = JsonUtils.parseByGson(response, RvStandardTypeBean.class);
                        if (beanBean.getCode().equals("0")) {
                            Officetype officetypes = new Officetype();
                            officetypes.setId("");
                            officetypes.setName("全部");
                            pop_mlist_type.add(officetypes);
                            for (int i = 0; i < rvStandardTypeBean.getData().getType().size(); i++) {
                                RvStandardTypeBean.DataBean.TypeBean typeBean = rvStandardTypeBean.getData().getType().get(i);
                                Officetype officetype = new Officetype();
                                officetype.setId(typeBean.getId() + "");
                                officetype.setName(typeBean.getName());
                                pop_mlist_type.add(officetype);
                            }
                        }
                    }
                });
    }

    @Override
    public int getItemLayoutId() {
        return R.layout.item_order_rv_info;
    }

    @Override
    public void request(int page) {

        OkHttpUtils.post()
                .url(Api.POST_ORDERINDEX)
                .addHeader("flag", SPUtils.get(getContext(), "token", "").toString())
                .addParams("day", all_type)
                .addParams("data", "" + data)
                .addParams("tid", tid)
                .addParams("bid", bid)
                .addParams("search", search)
                .addParams("begin", begin)
                .addParams("end", end)
                .addParams("director_id", ""+ director_id)
                .addParams("page",page+"")
                .tag(this)
                .build()
                .execute(new StringCallback() {
                    @Override
                    public void onError(Call call, Exception e, int id) {
                        Log.e("TAG", "全部订单onError   " + e.getMessage());
                        ToastUtils.s(getContext(),""+e.getMessage());
                        manager.releaseRefresh();
                    }

                    @Override
                    public void onResponse(String response, int id) {
                        Log.e("TAG", "全部订单onResponse   " + response);
                        manager.releaseRefresh();
                        BeanBean beanBean = JsonUtils.parseByGson(response, BeanBean.class);
                        if (beanBean.getCode().equals("4")) {
                            SPUtils.put(getContext(), "token", "");
                            Intent intent = new Intent(getContext(), LoginActivity.class).
                                    setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
                            startActivity(intent);
                            return;
                        }
                        FOrderAllBean fOrderAllBean = JsonUtils.parseByGson(response, FOrderAllBean.class);
                        if (fOrderAllBean.getCode().equals("0")) {
                            textFieldNumber.setText(fOrderAllBean.getData().getCount() + "");
                            textTableNumber.setText("" + fOrderAllBean.getData().getDesk());
                            textDepositNumber.setText("" + fOrderAllBean.getData().getDeposit());
                            textTotalAmount.setText("" + fOrderAllBean.getData().getCheck());
                            if(page==1){
                                manager.resetPage();
                            }
                            manager.setData(fOrderAllBean.getData().getList());
//                            manager.getAdapter().notifyDataSetChanged();
                        }
                    }
                });
    }

    @Override
    public void fillView(BaseViewHolder holder, FOrderAllBean.DataBean.ListBean item) {
        TextView text_date = holder.itemView.findViewById(R.id.text_date);
        TextView text_office = holder.itemView.findViewById(R.id.text_office);
        TextView text_user_name = holder.itemView.findViewById(R.id.text_user_name);
        TextView text_type = holder.itemView.findViewById(R.id.text_type);
        TextView text_phone = holder.itemView.findViewById(R.id.text_phone);

        text_date.setTextColor(getResources().getColor(R.color.color_010000));
        text_office.setTextColor(getResources().getColor(R.color.color_010000));
        text_user_name.setTextColor(getResources().getColor(R.color.color_010000));
        text_type.setTextColor(getResources().getColor(R.color.color_010000));
        text_phone.setTextColor(getResources().getColor(R.color.color_010000));

        if (item.getIs_meeting() == 1) {
            if (item.getBegin_night() == 2) {
                if(data.equals("1")){
                    text_date.setText("" + item.getBegin() + "");
                }else{
                    text_date.setText("" + item.getBegin() + "\n下午");
                }

            } else {
                if(data.equals("1")){
                    text_date.setText("" + item.getBegin() + "");
                }else{
                    text_date.setText("" + item.getBegin() + "\n上午");
                }

            }
        } else {
            if (item.getBegin_night() == 2) {
                if(data.equals("1")){
                    text_date.setText("" + item.getBegin() + "");
                }else{
                    text_date.setText("" + item.getBegin() + "\n晚上");
                }

            } else {
                if(data.equals("1")){
                    text_date.setText("" + item.getBegin() + "");
                }else{
                    text_date.setText("" + item.getBegin() + "\n中午");
                }

            }
        }
        text_office.setText("" + item.getB_name());
        text_user_name.setText("" + item.getBook());
        text_type.setText("" + item.getT_name());
        text_phone.setText("" + item.getMobile());
        text_phone.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (DatePhotoUtils.isPhone(item.getMobile() + "")) {
                    DialPhoneDialog.show(getContext(),null,item.getMobile()+"");
                } else {
                    ToastUtils.s(getContext(), "手机号有误");
                }
            }
        });
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ReserveInformationActivity.start(item.getId() + "", "" + item.getIs_del());
            }
        });
    }

    @Override
    public void fillMuteView(BaseViewHolder helper, FOrderAllBean.DataBean.ListBean listBean) {

    }

    @Override
    public void attachActivity(AppCompatActivity activity) {

    }

    @Override
    public void dettachActivity() {

    }

    @Override
    public RecyclerView.LayoutManager getLayoutManager() {
        return new LinearLayoutManager(getContext());
    }

    @Override
    public boolean isMuteAdapter() {
        return false;
    }

    @Override
    public int[] getMuteTypes() {
        return new int[0];
    }

    @Override
    public int[] getMuteLayouts() {
        return new int[0];
    }


    public class Officetype {
        private String name;
        private String id;

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }

        public String getId() {
            return id;
        }

        public void setId(String id) {
            this.id = id;
        }
    }


    @Override
    public void onHiddenChanged(boolean hidden) {
        super.onHiddenChanged(hidden);
        if (hidden) {
            if (EventBus.getDefault().isRegistered(this)) {
                EventBus.getDefault().unregister(this); //解除注册
            }
        } else {
            if (EventBus.getDefault().isRegistered(this)) {
                EventBus.getDefault().unregister(this); //解除注册
                EventBus.getDefault().register(this);  //事件的注册
            } else {
                EventBus.getDefault().register(this);  //事件的注册
            }

        }
    }

    // 普通事件的处理
    @Subscribe(threadMode = ThreadMode.MAIN)
    public void handleEvent(EventBusBean carrier) {
        if (carrier != null) {
            if (carrier.getType() == 8) {
                if (carrier.getDid() != null && !carrier.getDid().equals("")) {
                    begin = "";
                    end = "";
                    director_id = carrier.getDid();
                }
            }
            if (carrier.getType() == 3) {
                all_type = "";
                if (data_type == 1) {
                    textStartTime.setText("" + carrier.getStarttime());
                } else {
                    timeEndTime.setText("" + carrier.getStarttime());
                }
                tabs.setSelectedTabIndicatorColor(Color.parseColor("#FFFFFF"));
                tabs.setTabTextColors(Color.parseColor("#707171"), Color.parseColor("#707171"));
            }
            begin = textStartTime.getText().toString();
            end = timeEndTime.getText().toString();

            request(1);
        }
    }


    @OnClick({R.id.text_all_office, R.id.text_all_type})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.text_all_office://全部 宴会厅
                showPopwindowAllOffice();
                break;
            case R.id.text_all_type://全部 类型
                showPopwindowAllType();
                break;
        }
    }

    //全部 类型
    private void showPopwindowAllType() {
        View popview = getLayoutInflater().inflate(R.layout.item_popwindow, null);
        RecyclerView recyclerView = popview.findViewById(R.id.rv_pop_info);
        recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
        RBaseAdapter<Officetype> rBaseAdapterAllType = new RBaseAdapter<Officetype>(getContext(), R.layout.item_item_popwindow, pop_mlist_type) {
            @Override
            protected void fillItem(RViewHolder holder, Officetype item, int position) {
                TextView text_title = holder.itemView.findViewById(R.id.text_title);
                text_title.setText(pop_mlist_type.get(position).getName());
                holder.itemView.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        tid = item.getId();
                        request(1);
                        mpopup_all_type.dismiss();
                    }
                });
            }

            @Override
            protected int getViewType(Officetype item, int position) {
                return 0;
            }
        };
        recyclerView.setAdapter(rBaseAdapterAllType);
        mpopup_all_type = new PopupWindow(popview, textAllType.getWidth(), ViewGroup.LayoutParams.WRAP_CONTENT);
        mpopup_all_type.setOutsideTouchable(true);
        mpopup_all_type.setFocusable(true);
        mpopup_all_type.showAsDropDown(textAllType);
    }

    //全部 宴会厅
    private void showPopwindowAllOffice() {
        View popview = getLayoutInflater().inflate(R.layout.item_popwindow, null);
        RecyclerView recyclerView = popview.findViewById(R.id.rv_pop_info);
        recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
        RBaseAdapter<Officetype> rBaseAdapterAllOffice = new RBaseAdapter<Officetype>(getContext(), R.layout.item_item_popwindow, pop_mlist_office) {
            @Override
            protected void fillItem(RViewHolder holder, Officetype item, int position) {
                TextView text_title = holder.itemView.findViewById(R.id.text_title);
                text_title.setText(pop_mlist_office.get(position).getName());
                holder.itemView.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        bid = item.getId();
//                        showOfficeType(item.getId());
                        request(1);
                        mpopup_all_office.dismiss();
                    }
                });
            }

            @Override
            protected int getViewType(Officetype item, int position) {
                return 0;
            }
        };
        recyclerView.setAdapter(rBaseAdapterAllOffice);
        mpopup_all_office = new PopupWindow(popview, textAllOffice.getWidth(), ViewGroup.LayoutParams.WRAP_CONTENT);
        mpopup_all_office.setOutsideTouchable(true);
        mpopup_all_office.setFocusable(true);
        mpopup_all_office.showAsDropDown(textAllOffice);
    }

}